package cn.pugle.base;

import static java.lang.Integer.MAX_VALUE;

/**
 * @author tzp
 * @since 2019/6/26
 */
public class Hash<K, V> {


    public int getPartition(K key, V value,
                            int numReduceTasks) {
        return (key.hashCode() & MAX_VALUE) % numReduceTasks;
    }

    /**
     * why xx & Integer.MAX_VALUE
     */
    public static void main(String[] args) {
        System.out.println(MAX_VALUE + 1);
        System.out.printf("%x\n", MAX_VALUE + 1);
        System.out.printf("%x\n", (MAX_VALUE + 1) & MAX_VALUE);
        System.out.printf("%x\n", -2);
        System.out.printf("%x\n", -2 & MAX_VALUE);
    }
}
